package com.example.easycharge.errorHandler;

import com.example.easycharge.error.NoTokenError;
import com.example.easycharge.interceptor.AuthenticationInterceptor;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice(assignableTypes = {AuthenticationInterceptor.class})
public class AuthorityErrorHandler {
    @ExceptionHandler(NoTokenError.class)
    @ResponseStatus(HttpStatus.FORBIDDEN)
    public ErrorResponse noTokenError() {
        ErrorResponse errorResponse = new ErrorResponse();
        errorResponse.setErrorCode(40100);
        errorResponse.setErrorMessage("无token，请登录");
        return errorResponse;
    }
}
